package com.jinxinol.core.common;

import javax.servlet.http.HttpServletRequest;

import net.fckeditor.handlers.PropertiesLoader;
import net.fckeditor.requestcycle.UserPathBuilder;

import com.jinxinol.basic.system.domain.SysUser;

public class FckPathBuilder implements UserPathBuilder {

	// 虚拟目录设置
	//实际的路径
	public String getUserFilesAbsolutePath(HttpServletRequest request) {

		
		StringBuffer userFilesPathBuffer = new StringBuffer();

		// 获得定义connector.userFilesPath的值
		String path = PropertiesLoader.getProperty("connector.userFilesPath");
		userFilesPathBuffer.append(path);
		userFilesPathBuffer.append("/");

		SysUser user = (SysUser) request.getSession().getAttribute("user");
		String userPath = "userDefault";
		if (user != null) {
			userPath = String.valueOf(user.getId());
		}
		userFilesPathBuffer.append(userPath);

		return userFilesPathBuffer.toString();
	}

	// FCK目录设置
	//读取的路径
	public String getUserFilesPath(HttpServletRequest request) {

		StringBuffer userFilesPathBuffer = new StringBuffer();
		String context = request.getContextPath();
		userFilesPathBuffer.append(context);
		// 获得定义connector.userFilesPath的值
		String path = PropertiesLoader.getProperty("connector.userFilesPath");
		userFilesPathBuffer.append(path);
		userFilesPathBuffer.append("/");

		SysUser user = (SysUser) request.getSession().getAttribute("user");
		String userPath = "userDefault";
		if (user != null) {
			userPath = String.valueOf(user.getId());
		}
		userFilesPathBuffer.append(userPath);

		return userFilesPathBuffer.toString();

	}

}
